#include "stdafx.h"
#include "ParticleEffector.h"
#include "Particle.h"
#include "..\..\EdgeMath\Vectors.h"
#include "..\..\EdgeMath\Math.h"
#include "..\..\EdgeMath\VectorHelper.h"

using namespace VectorHelper;

ParticleEffector::ParticleEffector(void)
{
	lifetime = 100.f;
}

ParticleEffector::ParticleEffector(Sphere3D& sphere)
{
	lifetime = 100.f;
	this->sphere = sphere;
}

void ParticleEffector::Effect(Particle* particle)
{
	// compute the distance to the particle
	float distance = Distance(particle->position, sphere.center);
	// ignore this particle if it's out of range
	if (distance > sphere.radius)
		return;

	// find the ammount of effect this effector has on the particle
	float effect = 1.f - Math::Clamp(distance / sphere.radius, 0.f, 1.f);

	// modify the values of the particle based on distance
	particle->acceleration = vector_3::Lerp(particle->acceleration, acceleration, effect);
	particle->end_alpha = Math::lerp(particle->end_alpha, alpha, effect);
	particle->end_color = vector_4::Lerp(particle->end_color, color, effect);
	particle->end_size = Math::lerp(particle->end_size, size, effect);
	// particle->lifetime = Math::lerp(particle->lifetime, lifetime, effect);
	particle->velocity = vector_3::Lerp(particle->velocity, velocity, effect);
	particle->rotation = Math::lerp(particle->rotation, rotation, effect);
	particle->rotation_speed = Math::lerp(particle->rotation_speed, rotation_speed, effect);
}